/**   
* @Title: MainProjectCreateLogic.java 
* @Package cn.com.gome.generator.logic 
* @Description: 主项目创建
* @author chenmin-ds   
* @date 2017年5月26日 下午2:49:05 
* @company cn.com.gome
* @version V1.0   
*/ 


package cn.com.gome.generator.logic;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import cn.com.gome.framework.dao.entity.TblChildProjectInfo;
import cn.com.gome.framework.dao.entity.TblProjectBasicInfo;

import com.gomeplus.frame.exception.LogicsException;
import com.gomeplus.frame.logic.ILogics;
import com.gomeplus.frame.logic.ResultEnum;

/** 
 * @ClassName: MainProjectCreateLogic 
 * @Description: 主项目创建
 * @author chenmin-ds 
 * @date 2017年5月26日 下午2:49:05  
 */
@Service
public class ChildProjectWebCreateLogic implements ILogics<Map<String , Object>> {

	private Logger logger = LoggerFactory.getLogger("ChildProjectAdminCreateLogic");
	
	public ResultEnum exec(Map<String , Object> map) throws LogicsException {
		try{
			TblChildProjectInfo childProjectInfo = (TblChildProjectInfo) map.get("childProjectInfo");
			TblProjectBasicInfo projectBasicInfo = (TblProjectBasicInfo) map.get("projectBasicInfo");
			String pachagesPath = projectBasicInfo.getPackages().replace(".", "//");
			
			String projectPath = projectBasicInfo.getProjectPath().trim();
			if(!projectPath.endsWith("//")){
				projectPath +="//";
				projectBasicInfo.setProjectPath(projectPath);
			}
			
			projectPath += projectBasicInfo.getProjectEng()+"//";
			projectPath += projectBasicInfo.getProjectEng()+"-"+childProjectInfo.getChildProjectEng();
			childProjectInfo.setProjectPath(projectPath);
			File file = new File(projectPath+"//src//main//resources//spring.xml");
			if (!file.exists()) {
				file.createNewFile();
			}
			StringBuffer sb = new StringBuffer();
			sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n");
			sb.append("<beans xmlns=\"http://www.springframework.org/schema/beans\" \n");
			sb.append("			xmlns:util=\"http://www.springframework.org/schema/util\" \n");
			sb.append("			xmlns:aop=\"http://www.springframework.org/schema/aop\" \n");
			sb.append("			xmlns:context=\"http://www.springframework.org/schema/context\" \n");
			sb.append("			xmlns:tx=\"http://www.springframework.org/schema/tx\" \n");
			sb.append("			xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n");
			sb.append("			xmlns:mongo=\"http://www.springframework.org/schema/data/mongo\" \n");
			sb.append("			xmlns:task=\"http://www.springframework.org/schema/task\" \n");
			sb.append("			xsi:schemaLocation=\"http://www.springframework.org/schema/aop \n");
			sb.append("								http://www.springframework.org/schema/aop/spring-aop.xsd \n");
			sb.append("								http://www.springframework.org/schema/beans \n");
			sb.append("								http://www.springframework.org/schema/beans/spring-beans.xsd\n"); 
			sb.append("								http://www.springframework.org/schema/context \n");
			sb.append("								http://www.springframework.org/schema/context/spring-context.xsd \n");
			sb.append("								http://www.springframework.org/schema/tx \n");
			sb.append("								http://www.springframework.org/schema/tx/spring-tx.xsd \n");
			sb.append("								http://www.springframework.org/schema/task \n");
			sb.append("								http://www.springframework.org/schema/task/spring-task-3.1.xsd \n");
			sb.append("								http://www.springframework.org/schema/util \n");
			sb.append("								http://www.springframework.org/schema/util/spring-util-3.1.xsd\">\n");
			sb.append("  \n");
			sb.append("  <aop:aspectj-autoproxy proxy-target-class=\"true\" /> \n");
			sb.append("  <context:annotation-config /> \n");
			if("com.gomeplus".equals(projectBasicInfo.getPackages())){
				sb.append("  <context:component-scan base-package=\"com.gomeplus\" /> \n");
			}else{
				sb.append("  <context:component-scan base-package=\""+projectBasicInfo.getPackages()+",com.gomeplus\" /> \n");
			}
			sb.append("  \n");
			sb.append("  <import resource=\"classpath*:/frame/ftl-frame-servlet.xml\" /> \n");
			sb.append("  <import resource=\"classpath:/spring/spring-mvc-interceptor.xml\" /> \n");
			sb.append("  <bean id=\"springBeanFactory\" class=\"com.gomeplus.frame.factory.SpringBeanFactory\" /> \n");
			sb.append("  \n");
			sb.append("  \n");
			sb.append("  <import resource=\"classpath*:/dubbo/dubbo-head.xml\" /> \n");
			sb.append("  <import resource=\"classpath*:/"+projectBasicInfo.getProjectEng()+"/"+projectBasicInfo.getProjectEng()+"-dubbo-consumer.xml\" /> \n");
			sb.append("  <import resource=\"spring/redis-dubbo-consumer.xml\" /> \n");
			sb.append("</beans>\n");
			OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//resources//spring.xml"), "UTF-8");
			BufferedWriter writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			file = new File(projectPath+"//src//main//resources//log4j.properties");
			if (!file.exists()) {
				file.createNewFile();
			}
			sb = new StringBuffer();
			sb.append("log4j.rootLogger=DEBUG,stdout\n");                                                         
			sb.append(" \n");                                                                                                  
			sb.append("log4j.appender.stdout=org.apache.log4j.ConsoleAppender\n");                                             
			sb.append("log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\n");                                        
			sb.append("log4j.appender.stdout.DatePattern='_'yyyy-MM-dd'.log'\n");                                              
			sb.append("log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH\\:mm\\:ss} %p [%c] %m%n\n");              
			sb.append("      \n");                                                                                             
			sb.append("log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender\n");                              
			sb.append("log4j.appender.fileAppender.File=../logs/"+projectBasicInfo.getProjectEng()+"_web_info.log\n");                                 
			sb.append("log4j.appender.fileAppender.DatePattern='_'yyyy-MM-dd'.log'\n");                                        
			sb.append("log4j.appender.fileAppender.Threshold=INFO\n");                                                         
			sb.append("log4j.appender.fileAppender.Encoding=UTF-8\n");                                                         
			sb.append("log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout\n");                                  
			sb.append("log4j.appender.fileAppender.layout.ConversionPattern=%-d{yyyyMMdd HH:mm:ss SSS}-->[%-5p]--[%c{1}]--%m%\n"); 
			sb.append("\n");                                                                                                   

			write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//resources//log4j.properties"), "UTF-8");
			writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			file = new File(projectPath+"//src//main//resources//spring");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//resources//spring//redis-dubbo-consumer.xml");
			if (!file.exists()) {
				file.createNewFile();
			}
			sb = new StringBuffer();
			sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
			sb.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"\n");
			sb.append("	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dubbo=\"http://code.alibabatech.com/schema/dubbo\"\n");
			sb.append("	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\n");
			sb.append("	http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd\">\n");
			sb.append("	<bean id=\"jjcsGcache\" class=\"redis.GcacheClient\" destroy-method=\"close\">\n");
			sb.append("	<!-- zookeeperAddress -->\n");
			sb.append("	<constructor-arg value=\"${dubbo.run.redis}\" />\n");
			sb.append("	<!-- businessName -->\n");
			sb.append("	<constructor-arg value=\"${redis.businessName}\" />\n");
			sb.append("	</bean>\n");
			sb.append("</beans>\n");
			write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//resources//spring//redis-dubbo-consumer.xml"), "UTF-8");
			writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			file = new File(projectPath+"//src//main//resources//props//dev");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//resources//props//dev//"+projectBasicInfo.getProjectEng()+"-web.properties");
			if (!file.exists()) {
				file.createNewFile();
			}
			file = new File(projectPath+"//src//main//resources//props//uat");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//resources//props//uat//"+projectBasicInfo.getProjectEng()+"-web.properties");
			if (!file.exists()) {
				file.createNewFile();
			}
			file = new File(projectPath+"//src//main//resources//props//live");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//resources//props//live//"+projectBasicInfo.getProjectEng()+"-web.properties");
			if (!file.exists()) {
				file.createNewFile();
			}
			file = new File(projectPath+"//src//main//resources//props//pre");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//resources//props//pre//"+projectBasicInfo.getProjectEng()+"-web.properties");
			if (!file.exists()) {
				file.createNewFile();
			}
			
			file = new File(projectPath+"//src//main//resources//props//"+projectBasicInfo.getProjectEng()+"-web.properties");
			if (!file.exists()) {
				file.createNewFile();
			}
			file = new File(projectPath+"//src//main//webapp//js");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//webapp//css");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//webapp//images");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//webapp//WEB-INF//page");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//webapp//WEB-INF//web.xml");
			if (!file.exists()) {
				file.createNewFile();
			}
			sb = new StringBuffer();
			sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
			sb.append("<web-app xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n");     
			sb.append("	xmlns=\"http://java.sun.com/xml/ns/javaee\" \n");     
			sb.append("	xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\" \n");     
			sb.append("	version=\"2.5\" metadata-complete=\"true\">\n");         
			sb.append("  <context-param>\n");     
			sb.append("  	<param-name>propertiesConfigLocation</param-name> \n");     
			sb.append("  	<param-value>/props/"+projectBasicInfo.getProjectEng()+"-web.properties</param-value>\n");      
			sb.append("  </context-param>\n");     
			sb.append("  <listener>\n");     
			sb.append("  	<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> \n");     
			sb.append("  </listener>\n");     
			sb.append("  <listener>\n");     
			sb.append("  	<listener-class>com.gomeplus.frame.listener.PropertiesConfigListener</listener-class> \n");     
			sb.append("  </listener>\n");     
			sb.append("  <servlet>\n");
			sb.append("  	<servlet-name>springmvc</servlet-name> \n");
			sb.append("  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>\n"); 
			sb.append("  	<init-param>\n");
			sb.append("  		<param-name>publishContext</param-name> \n");
			sb.append("  		<param-value>false</param-value> \n");
			sb.append("  	</init-param>\n");
			sb.append("  	<init-param>\n");
			sb.append("  		<param-name>contextConfigLocation</param-name> \n");
			sb.append("  		<param-value>classpath:spring.xml</param-value> \n");
			sb.append("  	</init-param>\n");
			sb.append("  	<load-on-startup>1</load-on-startup> \n");
			sb.append("  </servlet>\n");
			sb.append("  <servlet-mapping>\n");
			sb.append("  	<servlet-name>springmvc</servlet-name> \n");
			sb.append("  	<url-pattern>*.dhtml</url-pattern> \n");
			sb.append(" 	 <url-pattern>*.json</url-pattern> \n");
			sb.append("  </servlet-mapping>\n");
			sb.append("  <filter>\n");
			sb.append("  	<filter-name>HiddenHttpMethodFilter</filter-name> \n");
			sb.append("  	<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> \n");
			sb.append("  	<async-supported>true</async-supported> \n");
			sb.append("  </filter>\n");
			sb.append("  <filter-mapping>\n");
			sb.append("  	<filter-name>HiddenHttpMethodFilter</filter-name> \n");
			sb.append("  	<servlet-name>springmvc</servlet-name> \n");
			sb.append("  </filter-mapping>\n");
			sb.append("  <filter>\n");
			sb.append("  	<filter-name>EncodingFilter</filter-name> \n");
			sb.append("  	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> \n");
			sb.append("  	<async-supported>true</async-supported> \n");
			sb.append("  	<init-param>\n");
			sb.append("  		<param-name>encoding</param-name> \n");
			sb.append("  		<param-value>UTF-8</param-value> \n");
			sb.append(" 	</init-param>\n");
			sb.append("  </filter>\n");
			sb.append("  <filter-mapping>\n");
			sb.append("  	<filter-name>EncodingFilter</filter-name> \n");
			sb.append("  	<url-pattern>/*</url-pattern> \n");
			sb.append("  </filter-mapping>\n");
			sb.append("  <error-page>\n");
			sb.append("  	<error-code>404</error-code> \n");
			sb.append("  	<location>/resultController/404error.dhtml</location> \n");
			sb.append("  </error-page>\n");
			sb.append("  <error-page>\n");
			sb.append("  	<error-code>500</error-code> \n");
			sb.append("  	<location>/resultController/500error.dhtml</location> \n");
			sb.append("  </error-page>\n");
			sb.append("</web-app>\n");  
			write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//webapp//WEB-INF//web.xml"), "UTF-8");
			writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			file = new File(projectPath+"//src//main//resources//spring//spring-mvc-interceptor.xml");
			if (!file.exists()) {
				file.createNewFile();
			}
			sb = new StringBuffer();
			sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); 
			sb.append(" <beans xmlns=\"http://www.springframework.org/schema/beans\"\n"); 
			sb.append("	 xmlns:util=\"http://www.springframework.org/schema/util\" \n");
			sb.append("	 xmlns:aop=\"http://www.springframework.org/schema/aop\" \n");
			sb.append("	 xmlns:context=\"http://www.springframework.org/schema/context\" \n");
			sb.append("	 xmlns:tx=\"http://www.springframework.org/schema/tx\" \n");
			sb.append("	 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n");
			sb.append("	 xmlns:mongo=\"http://www.springframework.org/schema/data/mongo\" \n");
			sb.append("	 xmlns:task=\"http://www.springframework.org/schema/task\" \n");
			sb.append("	 xmlns:mvc=\"http://www.springframework.org/schema/mvc\" \n");
			sb.append("	 xsi:schemaLocation=\"http://www.springframework.org/schema/aop \n");
			sb.append("		 http://www.springframework.org/schema/aop/spring-aop.xsd \n");
			sb.append("		 http://www.springframework.org/schema/beans \n");
			sb.append("		 http://www.springframework.org/schema/beans/spring-beans.xsd \n");
			sb.append("		 http://www.springframework.org/schema/context \n");
			sb.append("		 http://www.springframework.org/schema/context/spring-context.xsd \n");
			sb.append("		 http://www.springframework.org/schema/tx \n");
			sb.append("		 http://www.springframework.org/schema/tx/spring-tx.xsd \n");
			sb.append("		 http://www.springframework.org/schema/task \n");
			sb.append("		 http://www.springframework.org/schema/task/spring-task-3.1.xsd \n");
			sb.append("		 http://www.springframework.org/schema/util \n");
			sb.append("		 http://www.springframework.org/schema/util/spring-util-3.1.xsd \n");
			sb.append("		 http://www.springframework.org/schema/mvc \n");
			sb.append("		 http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd\">\n");
			sb.append("  <mvc:interceptors>\n");
			sb.append("  	<mvc:interceptor>\n");
			sb.append("  		<mvc:mapping path=\"/**/*\" /> \n");
			sb.append("  		<bean class=\""+projectBasicInfo.getPackages()+"."+projectBasicInfo.getProjectEng()+".web.interceptor.GomeUserLoginInterceptor\">\n");
			sb.append("  			<property name=\"allowUrls\">\n");
			sb.append("  				<list>\n");
			sb.append("  					<value>payController/404error.dhtml</value> \n");
			sb.append("  					<value>payController/500error.dhtml</value> \n");
			sb.append("  					<value>tests/tests.dhtml</value> \n");
			sb.append("  				</list>\n");
			sb.append("  			</property>\n");
			sb.append("  		</bean>\n");
			sb.append("  	</mvc:interceptor>\n");
			sb.append("  </mvc:interceptors>\n");
			sb.append("</beans>\n");
			write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//resources//spring//spring-mvc-interceptor.xml"), "UTF-8");
			writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			file = new File(projectPath+"//src//main//java//"+pachagesPath+"//"+projectBasicInfo.getProjectEng()+"//web//controller");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//java//"+pachagesPath+"//"+projectBasicInfo.getProjectEng()+"//web//interceptor");
			if (!file.exists()) {
				file.mkdirs();
			}
			file = new File(projectPath+"//src//main//java//"+pachagesPath+"//"+projectBasicInfo.getProjectEng()+"//web//util");
			if (!file.exists()) {
				file.mkdirs();
			}
			
			file = new File(projectPath+"//src//main//java//"+pachagesPath+"//"+projectBasicInfo.getProjectEng()+"//web//interceptor//GomeUserLoginInterceptor.java");
			if (!file.exists()) {
				file.createNewFile();
			}
			sb = new StringBuffer();
			sb.append("package "+projectBasicInfo.getPackages()+"."+projectBasicInfo.getProjectEng()+".web.interceptor;\n");
			sb.append("\n");
			sb.append("import java.io.IOException;\n");
			sb.append("import javax.servlet.http.HttpServletRequest;\n");
			sb.append("import javax.servlet.http.HttpServletResponse;\n");
			sb.append("import org.slf4j.Logger;\n");
			sb.append("import org.slf4j.LoggerFactory;\n");
			sb.append("import org.springframework.web.servlet.HandlerInterceptor;\n");
			sb.append("import org.springframework.web.servlet.ModelAndView;\n");
			sb.append("import com.gomeplus.frame.cache.GlobalApplicationCache;\n");
			sb.append("import com.gome.memberCore.lang.model.UserResult;\n");
			sb.append("import com.gome.sso.common.tools.SsoUserCookieTools;\n");
			sb.append("import com.gome.sso.model.UserCookie;\n");
			sb.append("\n");
			sb.append("public class GomeUserLoginInterceptor implements HandlerInterceptor{\n");
			sb.append("\n");
			sb.append("	private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());\n");
			sb.append("	\n");
			sb.append("	private String[] allowUrls = null;\n");
			sb.append("	\n");
			sb.append("	public String[] getAllowUrls() {\n");
			sb.append("		return allowUrls;\n");
			sb.append("	}\n");
			sb.append("\n");
			sb.append("	public void setAllowUrls(String[] allowUrls) {\n");
			sb.append("		this.allowUrls = allowUrls;\n");
			sb.append("	}\n");
			sb.append("	\n");
			sb.append("	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {\n");
			sb.append("		try {\n");
			sb.append("			logger.info(\"校验登录信息\");\n");
			sb.append("			String requestURI = request.getRequestURI();\n");
			sb.append("			if(allowUrls != null && allowUrls.length > 0){\n");
			sb.append("				for(String temp : allowUrls){\n");
			sb.append("					if(requestURI.indexOf(temp) >= 0 )\n");
			sb.append("						return true;\n");
			sb.append("				}\n");
			sb.append("			}\n");
			sb.append("			UserResult<UserCookie> userResult = SsoUserCookieTools.checkIsLoginByCookie(request, response);\n");
			sb.append("			if(!userResult.isSuccess()){\n");
			sb.append("				//如果没有登录，跳转到登录页面\n");
			sb.append("				return false;\n");
			sb.append("			}else{\n");
			sb.append("				String userId = userResult.getBuessObj().getId();//用户ID\n");
			sb.append("				String userLogin = userResult.getBuessObj().getLogin();\n");
			sb.append("				String userNm = userLogin;//默认值为用户账户\n");
			sb.append("				request.setAttribute(\"userId\", userId);\n");
			sb.append("				request.setAttribute(\"userLogin\", userLogin);\n");
			sb.append("				request.setAttribute(\"userNm\", userNm);\n");
			sb.append("				logger.info(\"用户登录成功:userId=\" + userId + \",userLogin=\" + userLogin);\n");
			sb.append("				return true;\n");
			sb.append("			}\n");
			sb.append("		} catch (Exception e) {\n");
			sb.append("			logger.error(\"未登录，重定向异常\",e);\n");
			sb.append("			try {\n");
			sb.append("				response.sendRedirect((String)GlobalApplicationCache.getInstance().get(\"GOME_PAGE_URL\"));\n");
			sb.append("			} catch (IOException e1) {\n");
			sb.append("				logger.error(\"未登录，再次重定向异常\",e1);\n");
			sb.append("			}\n");
			sb.append("		}\n");
			sb.append("		logger.info(\"用户未登录\");\n");
			sb.append("		return false;\n");
			sb.append("	}\n");
			sb.append("\n");
			sb.append("	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,\n");
			sb.append("			ModelAndView modelAndView) throws Exception {}\n");
			sb.append("\n");
			sb.append("	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)\n");
			sb.append("			throws Exception {}\n");
			sb.append("\n");
			sb.append("}\n");
			write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//java//"+pachagesPath+"//"+projectBasicInfo.getProjectEng()+"//web//interceptor//GomeUserLoginInterceptor.java"), "UTF-8");
			writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			file = new File(projectPath+"//src//main//java//"+pachagesPath+"//"+projectBasicInfo.getProjectEng()+"//web//controller//TestsController.java");
			if (!file.exists()) {
				file.createNewFile();
			}
			sb = new StringBuffer();
			sb.append("package "+projectBasicInfo.getPackages()+"."+projectBasicInfo.getProjectEng()+".web.controller;\n");
			sb.append("\n");     
			sb.append("import javax.servlet.http.HttpServletRequest;\n");     
			sb.append("import javax.servlet.http.HttpServletResponse;\n");     
			sb.append("\n");     
			sb.append("import org.springframework.stereotype.Controller;\n");     
			sb.append("import org.springframework.ui.Model;\n");     
			sb.append("import org.springframework.web.bind.annotation.RequestMapping;\n");     
			sb.append("\n");     
			sb.append("@Controller\n");     
			sb.append("@RequestMapping(\"/tests\")\n");     
			sb.append("public class TestsController {\n");     
			sb.append("\n");     
			sb.append("	@RequestMapping(\"/tests\")\n");     
			sb.append("	public String init(Model model,HttpServletRequest request, HttpServletResponse response) {\n");     
			sb.append("		\n");     
			sb.append("		return \"tests\";\n");     
			sb.append("	}\n");     
			sb.append("\n");     
			sb.append("}\n");  
			write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//java//"+pachagesPath+"//"+projectBasicInfo.getProjectEng()+"//web//controller//TestsController.java"), "UTF-8");
			writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			file = new File(projectPath+"//src//main//webapp//WEB-INF//page//tests.ftl");
			if (!file.exists()) {
				file.createNewFile();
			}
			sb = new StringBuffer();
			sb.append("项目生成成功");
			write = new OutputStreamWriter(new FileOutputStream(projectPath+"//src//main//webapp//WEB-INF//page//tests.ftl"), "UTF-8");
			writer = new BufferedWriter(write);
			writer.write(sb.toString());
			writer.flush();
			writer.close();
			
			return ResultEnum.OK;
		}catch(Exception e){
			logger.error("创建子项目异常：",e);
		}
		return ResultEnum.PART_CASE_01;
	}

}
